<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>教师代看课-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart id="xsqj" style="background: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<div class="weui_cells weui_cells_access ltbg borderLeft" style="margin-top:0;">
				<div class="listHead">
					<ul class="clearfix">
						<li class="on">我的申请</li>
						<li>我要审批</li>
					</ul>
				</div>
			</div>
			
	        <div class="weui_tab kcfd-list1" id="tab3">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item">
	                    	审核中(<span id="ingCount">0</span>)
	                </div>
	                <div class="weui_navbar_item" id="okList">
	                    	已同意
	                </div>
	                <div class="weui_navbar_item" id="noList">
	                    	已驳回
	                </div>
	            </div>
	            <div class="weui_tab_bd">
	                
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="ingItem">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
			        
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="okItem">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
		            
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="noItem">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
	            </div>
	        </div>
	        
	        <div class="weui_tab kcfd-list1 hide" id="tab4">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item" id="approvalIngList">
	                    	待审核(<span id="approvalIngCount">0</span>)
	                </div>
	                <div class="weui_navbar_item" id="approvalOkList">
	                    	已同意
	                </div>
	                <div class="weui_navbar_item" id="approvalNoList">
	                    	已驳回
	                </div>
	            </div>
	            <div class="weui_tab_bd">
	                
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="approvalIngItem">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
			        
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="approvalOkItem">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
		            
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="approvalNoItem">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
	            </div>
	        </div>
	        
	       <a href="<%=basePath %>/ls/teacher/change/course/publish" style="display: block;">
		       <div class="addBtnnew">
					<div class="linea"></div>
					<div class="lineb"></div>
		       </div>
	       </a>
		</div>
	</div>
	
	<script id="apply-table-template" type="text/x-handlebars-template">	
	{{#each rows}}
	<a class="weui_cell weui_media_box weui_media_text" href="<%=basePath%>/ls/teacher/change/course/detail/{{id}}">                        
		<div class="weui_cell_bd weui_cell_primary">                    		
			<p class="weui_media_desc f18 f-black">申请人：{{applyTeacherName}}</p>                    		
			<p class="weui_media_desc mt10">事由：{{reason}}</p>                    		
			<p class="weui_media_desc mt10">申请时间：{{dateFormat createTime}}</p>                		
		</div>                		
		<span class="weui_cell_ft"></span>            		
	 </a>
     {{/each}}
 </script>
 
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
		var isLoadApprovalOkList = false, isLoadApprovalNoList = false,
			isLoadIngList = false, isLoadOkList = false, isLoadNoList = false;
		var approvalIngPage = 1, approvalIngRows = 10,
			approvalOkPage = 1, approvalOkRows = 10,
			approvalNoPage = 1, approvalNoRows = 10,
			ingPage = 1,ingRows = 10,
			okPage = 1, okRows = 10, 
			noPage = 1, noRows = 10;
		$(function() {
			$('#tab3').tab({
				defaultIndex: 0,
				activeClass: "tab-blue "
			});
			$('#tab4').tab({
				defaultIndex: 0,
				activeClass: "tab-blue "
			});
			$(".listHead li").click(function(){
				var obj = $(this);
				var index = obj.index();
				$(".ltbg-content").eq(index).show().siblings(".ltbg-content").hide();
				obj.addClass("on").siblings().removeClass("on")
				if(index == 0) {
					$("#tab3").show();
					$("#tab4").hide();
					$(".addBtnnew").show();
				}
				else if(index == 1) {
					$("#tab3").hide();
					$("#tab4").show();
					$(".addBtnnew").hide();
					if(!isLoadIngList) {
						isLoadIngList = true;
						var param = {
							page: approvalIngPage,
							rows: approvalIngRows,
							type: 1,
							replaceTeacherId: "${user.teacher.id}"
						}
						ingPage += 1;
						loadItem(param, "approvalIngItem");
					}
				}
			})

			$("#approvalOkList").click(function() {
				if(!isLoadApprovalOkList){
					isLoadApprovalOkList = true;
					var param = {
						page: approvalOkPage,
						rows: approvalOkRows,
						type: 2,
						replaceTeacherId: "${user.teacher.id}"
					}
					approvalOkPage += 1;
					loadItem(param, "approvalOkItem");
				}
			})
			$("#approvalNoList").click(function() {
				if(!isLoadApprovalNoList){
					isLoadApprovalNoList = true;
					var param = {
						page: approvalNoPage,
						rows: approvalNoRows,
						type: 3,
						replaceTeacherId: "${user.teacher.id}"
					}
					approvalNoPage += 1;
					loadItem(param, "approvalNoItem");
				}
			})
			$("#okList").click(function() {
				if(!isLoadOkList){
					isLoadOkList = true;
					var param = {
						page: okPage,
						rows: okRows,
						type: 2,
						applyTeacherId: "${user.teacher.id}"
					}
					okPage += 1;
					loadItem(param, "okItem");
				}
			})
			$("#noList").click(function() {
				if(!isLoadNoList){
					isLoadNoList = true;
					var param = {
						page: noPage,
						rows: noRows,
						type: 3,
						applyTeacherId: "${user.teacher.id}"
					}
					noPage += 1;
					loadItem(param, "noItem");
				}
			})
			$(".dropload-down").on("click", ".dropload-hasData", function() {
				var id = $(this).closest(".weui_tab_bd_item").find(".weui_panel_bd").attr("id");
				var param = {};
				if(id == 'ingItem') {
					param.page = ingPage;
					param.rows = ingRows;
					param.type = 1;
					param.applyTeacherId = "${user.teacher.id}";
					ingPage += 1;
				}else if(id == 'okItem') {
					param.page = okPage;
					param.rows = okRows;
					param.type = 2;
					param.applyTeacherId = "${user.teacher.id}";
					okPage += 1;
				}else if(id == 'noItem') {
					param.page = noPage;
					param.rows = noRows;
					param.type = 3;
					param.applyTeacherId = "${user.teacher.id}";
					noPage += 1;
				}else if(id == 'approvalIngItem') {
					param.page = approvalIngPage;
					param.rows = approvalIngRows;
					param.type = 1;
					param.exchangeTeacherId = "${user.teacher.id}";
					approvalIngPage += 1;
				}else if(id == 'approvalOkItem') {
					param.page = approvalOkPage;
					param.rows = approvalOkRows;
					param.type = 2;
					param.exchangeTeacherId = "${user.teacher.id}";
					approvalOkPage += 1;
				}else if(id == 'approvalNoItem') {
					param.page = approvalNoPage;
					param.rows = approvalNoRows;
					param.type = 3;
					param.exchangeTeacherId = "${user.teacher.id}";
					approvalNoPage += 1;
				}
				loadItem(param, id);
			})
			var param = {
				page: ingPage,
				rows: ingRows,
				type: 1,
				applyTeacherId: "${user.teacher.id}"
			}
			ingPage += 1;
			loadItem(param, "ingItem");
		});
		function loadItem(param, id) {
			var url = "/ls/teacher/change/course/pending/page";
			if(param.type == 2) url = "/ls/teacher/change/course/agree/page";
			if(param.type == 3) url = "/ls/teacher/change/course/reject/page";
			$.ajax({
				url: basePath + url,
				type: 'post',
				dataType: 'json',
				data: param,
				success: function(data) {
					if(id == "ingItem") {
						$("#ingCount").html(data.data.total);
					}else if(id == "approvalIngItem"){
						$("#approvalIngCount").html(data.data.total);
					}
					if(data.data.rows.length == 0 || param.page*param.rows >= data.data.total) {// 如果没有数据
	            		$("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
					}
					loadHtml(data.data, id);
				}
			});
		}
		
		function loadHtml(data, id) {
			var myTemplate = Handlebars.compile($("#apply-table-template").html());
			Handlebars.registerHelper("equal", function(v1,v2,options) {
				if(v1 == v2) {
					//满足添加继续执行
					return options.fn(this);
				}else {
					//不满足条件执行{{else}}部分
					return options.inverse(this);
				}
			});
			Handlebars.registerHelper("dateFormat", function(v1) {
				return getTime(v1, "yyyy/MM/dd hh:mm");
			});
			Handlebars.registerHelper("date1Format", function(v1) {
				return getTime(v1, "yyyy年MM月dd日");
			});
			
			Handlebars.registerHelper("statusFormat", function(v1,options) {
				if(v1 == '000') return "<img class='img-max' src='"+basePath+"/images/shenpitongguo.png'>";
				else if(v1 == '001') return "<img class='img-max' src='"+basePath+"/images/daish.png'>";
				else return "<img class='img-max' src='"+basePath+"/images/shenpibohui.png'>";
			});
			
			Handlebars.registerHelper("todateFormat", function(v1, v2) {
				return getTime(v1, "MM/dd hh:mm") + "-" + getTime(v2, "MM/dd hh:mm");
			});
			$('#' + id).append(myTemplate(data));
		}
</script>
</body>
</html>